# Python 2.6.4
# Project Euler, Problem 27
# Copyright 2010 Talha Zaman

from math import sqrt

def sieveprimes(limit):
    sieve = [0 for i in range(0, limit)]
    sieve[0] = sieve[1] = 1
    for i in range(2,limit):
        if sieve[i]: continue
        for j in range(2*i, limit, i):
            sieve[j] += 1
    return [x for x in range(limit) if sieve[x]==0]

def isprime(n, primes=[2,3,5,7], lim=10):
    if n < lim: return n in primes
    sn = sqrt(n)+1
    i=0
    while i in range(len(primes)) and primes[i]<=sn:
        if n%primes[i]==0: return False
        i += 1
    i = primes[len(primes)-1]
    while i<=sn:
        if n%i==0: return False
        i += 1
    return True

def consec(a, b):
    n = 0
    while isprime(n**2 + a*n + b): n += 1
    return n

p = sieveprimes(1000)
mc, ma, mb = 0, 0, 0
for a in range(-999,1000):
    for b in p:
        count = consec(a, b)
        if mc<count: mc, ma, mb = count, a, b
print mc, ma, mb
